<?php
/**
 * 信息维护 ajax类
 *
 * @package  ajax
 * @subpackage  backend
 * @create by allen.qiang
 */
header('Content-Type:text/html;charset=utf-8');

quanli_require('module/extend/project/project.class.php');

class ajax_projectList {

    public function execute() {

        if (isset($_REQUEST['operFlg']) && $_REQUEST['operFlg'] > 0) {

            switch($_REQUEST['operFlg']) {
				
                case 1: //项目列表
                    $this->ProjectList();
                    break;

                case 2: //项目添加
                    $this->ProjectAdd();
                    break;

                case 3 :
                	/**
                	 * 创建项目
                	 */
					$this->createProject();
                	break;
                	
                case 4 :
                	/**
                	 * 创建项目的测试环境
                	 */
                	$this->createProjectTestEnv();
                	break;
            }

        }

    }

   /**
    * 获取项目列表
    * */
    public function ProjectList(){
		
        global $G_SHOP;

        $projectObj = new project($G_SHOP);		
        $parms = array(
//        	'projectAlias' => $_REQUEST['projectName'],
			'projectAlias' => $_REQUEST['projectName'],
        	'rp'           => $_REQUEST['rp'],
        	'page'         => $_REQUEST['page'],
        	'sortname'     => $_REQUEST['sortname'],
        	'sortorder'    => $_REQUEST['sortorder'],
        	'query'        => $_REQUEST['query'],
        	'qtype'        => $_REQUEST['qtype']
        );

        $result = $projectObj->searchProject($parms);
        
        echo json_encode($result);
       
    }

    /**
     * 项目添加
     */
    private function ProjectAdd() {
		
        global $G_SHOP;
        
        //接收参数
        $projectName   = $_REQUEST['projectName'];
        $projectAlias   = $_REQUEST['projectAlias'];
        $projectTestEnvDomainName = $_REQUEST['projectTestEnvDomainName'];
     
        if(isset($projectName) && empty($projectName)){
    
        	 echo json_encode( array('message'=>'项目名称不能为空' , 'code'=>404 ) );
        	 return ;
        }
        
        if(isset($projectAlias) && empty($projectAlias)){
        	
        	echo json_encode( array('message' => '别名不能为空', 'code' => 404));
        	return ;
        }
        
        if(isset($projectTestEnvDomainName) && empty($projectTestEnvDomainName)){
        	
        	echo json_encode( array('message' => '测试环境域名不能为空', 'code' => 404));
        	return ;
        }
        
        $projectObj = new project($G_SHOP);
        
        $projectObj->addProjectName($projectName);
        $projectObj->addProjectAlias($projectAlias);
        $projectObj->addProjectTestEnvDomainName($projectTestEnvDomainName);
        
        $result = $projectObj->addCreateProject();
        echo json_encode($result);
        return ;
    }
	/**
	 * 创建项目
	 * */
	private function createProject(){
		
		global $G_SHOP;
		
		$projectObj = new project($G_SHOP);
		
		$result = $projectObj->createProject();
		echo json_encode($result);
		return ;
	}
	/**
	 * 创建测试环境
	 * */
	private function createProjectTestEnv(){
		
		global $G_SHOP;
		
		$projectObj = new project($G_SHOP);
		
		$result = $projectObj->createProjectTestEnv();
		
		echo json_encode($result);
		return ;
	}
}

?>